/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function (httpservice, $q, $http) {
    var workBarNoWorkService = {};
    //获取案件任务列表
    workBarNoWorkService.getWorkBarList = function (executorId) {
        var params = {"executorId": executorId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getWorkBarListUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //添加任务面板
    workBarNoWorkService.addWorkBarPanel = function (creatorId, panelName, sequence) {
        var params = {"creatorId": creatorId, "panelName": panelName, "sequence": sequence};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addWorkBarPanelUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    //获取用户任务列表
    workBarNoWorkService.getUserTaskList = function (params) {
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getUserTsakListUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
          // return response.data;
            deferred.resolve(response.data);
        }, function errorCallback(response) {
          // return response.data;
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //现在就做中添加>选着案件
    workBarNoWorkService.chooseTask = function (executorId) {
        var params = {"executorId": executorId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.taskCaseListUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    //现在就做中添加>选着阶段
    workBarNoWorkService.chooseJD = function (executorId) {
        var params = {"caseId": executorId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.taskCasePhaseUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //添加进程
    workBarNoWorkService.addTask = function (title, caseId, caseStageId, deadLine, executorId, creatorId, panelId,userName) {
        var params = {
            "title": title,
            "caseId": caseId,
            "caseStageId": caseStageId,
            "deadLine": deadLine,
            "executorId": creatorId,
            "creatorId": creatorId,
            "panelId": panelId,
            "userName":userName
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addJCTaskUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /*******************拖拽排序****************************************/
    workBarNoWorkService.getsortsortable = function (startArr) {
        /* taskId	int     	任务ID
         workBenchPanelId	Int	工作台任务面板ID*/
        // var params = {
        //     "taskId":id,
        //     "workBenchPanelId":uid ,
        //     "taskType": state
        // };

        var params = startArr;


        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.updateTaskWorkBenchUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /***********************************************************/


    //获取详情列表-----------证据

    //获取证据组接口列表
    workBarNoWorkService.getEGroupList = function (caseId) {
        var params={"caseId":caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEGroupUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //获取证据详情
    workBarNoWorkService.getEDetail = function (id) {
        var params = {"id": id};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEDetailUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //删除证据组
    workBarNoWorkService.deleteEGroup = function (id, creatorId) {
        var params = {"id": id, "status": "0", "creatorId": creatorId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEGroupUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //修改证据组名字
    workBarNoWorkService.updateEGroupName = function (id, evidenceGroupName, description, creatorId) {
        var params = {
            "id": id,
            "status": "1",
            "evidenceGroupName": evidenceGroupName,
            "description": "",
            "creatorId": creatorId
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEGroupUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //评论
    workBarNoWorkService.getEComment = function (evidenceId) {
        var params = {"evidenceId": evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getECommentUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //日志
    workBarNoWorkService.getELog = function (evidenceId) {
        var params = {"evidenceId": evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getELogUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //发布评论
    workBarNoWorkService.insertEComment = function (evidenceId, commentUserId, comment) {
        var params = {"evidenceId": evidenceId, "commentUserId": commentUserId, "comment": comment};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.insertECommentUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //详情修改
    workBarNoWorkService.updateEDetail = function (evidenceId, creatorId, status, evidenceTypeId, description, remark,evidenceGroupId,evidenceName) {
        var params = {
            "evidenceId": evidenceId,
            "creatorId": creatorId,
            "status": status,
            "evidenceTypeId": evidenceTypeId,
            "description": description,
            "remark": remark,
            "evidenceGroupId":evidenceGroupId,
            "evidenceName":evidenceName

        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.updateEDetailUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //详情删除
    workBarNoWorkService.deleteEDetail = function (evidenceId, creatorId) {
        var params = {"evidenceId": evidenceId, "creatorId": creatorId, "status": "0"};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteEDetailUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //修改证据任务状态
    workBarNoWorkService.updateEDDate = function (evidenceId) {
        var params = {"evidenceId": evidenceId, "status": "0"};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.updateETaskStatusUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //获取律师列表
    //workBarNoWorkService.getLawyers = function (caseId) {
    //    var params = {"caseId": caseId};
    //    var deferred = $q.defer();
    //    $http({
    //        method: 'POST',
    //        url: httpservice.getLawyersUrl,
    //        params: params,
    //        headers: {'Content-Type': 'application/json'}
    //    }).then(function successCallback(response) {
    //        deferred.resolve(response.data);
    //    }, function errorCallback(response) {
    //        deferred.reject(response);
    //    });
    //    return deferred.promise;
    //};

    //添加律师
    workBarNoWorkService.addLawyers = function (taskId, executorId, executorName, creatorId, evidenceId,loginName,evidenceName) {
        var params = {
            "taskId": taskId,
            "executorId": executorId,
            "executorName": executorName,
            "creatorId": creatorId,
            "evidenceId": evidenceId,
            "loginName":loginName,
            "evidenceName":evidenceName
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addLawyersUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //删除律师
    workBarNoWorkService.deleteLawyers = function (taskId, executorId, executorName, creatorId, evidenceId) {
        var params = {
            "taskId": taskId,
            "executorId": executorId,
            "executorName": executorName,
            "creatorId": creatorId,
            "evidenceId": evidenceId
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteLawyersUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //上传附件
    workBarNoWorkService.uploadFile = function (data) {
        //var params={"evidenceId":evidenceId,"creatorId":creatorId,"filename1":filename1};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.uploadFileUrl,
            data: data,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //下载附件
    workBarNoWorkService.downLoadFile = function (filename) {
        var params = {"filename": filename};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.downLoadFileUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
    //删除附件
    workBarNoWorkService.deleteFile = function (evidenceAttachedId, evidenceId, fileName, creatorId) {
        var params = {
            "evidenceAttachedId": evidenceAttachedId,
            "evidenceId": evidenceId,
            "fileName": fileName,
            "creatorId": creatorId
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.deleteFileUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };
//获取详情列表-----------证据


    //进程-----------进程
//获取详情列表
    workBarNoWorkService.getDetailList = function (taskId) {
        var params = {"taskId": taskId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getJCDetailUrl,
            params: params,
            // headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //详情上传描述或者日期
    workBarNoWorkService.updateDateOrDes = function (taskId, content, deadLine,title,creatorId,caseId,userName) {
        var params = {"taskId": taskId, "content": content, "deadLine": deadLine,"title":title,"creatorId":creatorId,"caseId":caseId,"userName":userName};
        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.updateDetailTaskUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //完成进程
    workBarNoWorkService.updateTask = function (taskId, status,title,creatorId,caseId,userName) {
        var params = {"taskId": taskId, "status": status,"title":title,"creatorId":creatorId,"caseId":caseId,"userName":userName};
        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.updateTaskUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //获取律师列表
    workBarNoWorkService.getLawyers = function (caseId) {
        var params = {"caseId": caseId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getLawyersUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 添加律师执行人
    workBarNoWorkService.addTaskLawyer = function (taskId, executorId,userId,userName) {
        var params = {"taskId": taskId, "executiveId": executorId,"userId":userId,"userName":userName};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.addTaskExecutorUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 删除律师执行人
    workBarNoWorkService.deleteTaskLawyer = function (lawyerId,userId,userName,executiveid,taskId) {
        var params={"id":lawyerId,"userId":userId,"userName":userName,"executiveId":executiveid,"taskId":taskId};
        var deferred = $q.defer();
        $http({
            method: 'DELETE',
            url: httpservice.deleteTaskExecutorUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //发说说
    workBarNoWorkService.sendJCComment = function (commentUserId, comment, taskId) {
        var params = {"commentUserId": commentUserId, "comment": comment, "taskId": taskId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.sendJCCommentUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 获取任务日志
    workBarNoWorkService.getTaskLog = function (taskId) {
        var params = {"taskId": taskId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getTaskLogListUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 上传附件
    workBarNoWorkService.uploadAppendix = function (fileData) {
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.uploadTaskFileUrl,
            data: fileData,
            headers: {'Content-Type': undefined},
            transformRequest: angular.identity
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 下载附件
    workBarNoWorkService.downloadAppendix = function (fileName) {
        var params = {"fileName": fileName};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.downLoadTaskFileUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    // 删除附件
    workBarNoWorkService.deleteTaskAppendix = function (fileId, fileName, taskId, creatorId) {
        var params = {"taskAttsId": fileId, "fileName": fileName, "taskId": taskId, "creatorId": creatorId};
        var deferred = $q.defer();
        $http({
            method: 'DELETE',
            url: httpservice.deleteTaskFileUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /*证据分组*/
    workBarNoWorkService.getETypeList = function () {
        //var params={"caseId":caseId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getETypeUrl,
            //params:params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //修改案件本名字
    workBarNoWorkService.updatePanelName = function (panelId, panelName) {
        var params = {"panelId": panelId, "panelName": panelName};
        var deferred = $q.defer();
        $http({
            method: 'PUT',
            url: httpservice.updatePanelNameUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    //删除面板
    workBarNoWorkService.deletePanel = function (panelId) {
        var params = {"panelId": panelId};
        var deferred = $q.defer();
        $http({
            method: 'DELETE',
            url: httpservice.deletePanelUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };



    return workBarNoWorkService;
}
